﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using ColorCode;

namespace AnglicanGeek.LiveWriter
{
    public partial class InsertSourceCodeDialog : Form, IInsertSourceCodeDialog
    {
        public InsertSourceCodeDialog()
        {
            InitializeComponent();
        }

        public ILanguage Language { get; private set; }
        public string SourceCode { get; private set; }

        public void SetLanguageChoices(IEnumerable<ColorCode.ILanguage> languages)
        {
            foreach (var language in languages)
                LanguageChoices.Items.Add(language);
        }

        public new DialogResult Show(IWin32Window dialogOwner)
        {
            return ShowDialog(dialogOwner);
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            SourceCode = SourceCodeInput.Text;
            Language = LanguageChoices.SelectedItem as ILanguage;

            DialogResult = DialogResult.OK;
        }

        private void SourceCodeInput_TextChanged(object sender, EventArgs e)
        {
            OKButton.Enabled = SourceCodeInput.Text.Trim() != string.Empty && LanguageChoices.SelectedItem != null;
        }

        private void LanguageChoices_SelectedIndexChanged(object sender, EventArgs e)
        {
            OKButton.Enabled = SourceCodeInput.Text.Trim() != string.Empty && LanguageChoices.SelectedItem != null;
        }
    }
}
